//
//  ThirtyoneViewController.m
//  Depressed.domo
//
//  Created by rimi on 16/5/27.
//  Copyright © 2016年 薛涛. All rights reserved.
//

#import "ThirtyoneViewController.h"
@interface ThirtyoneViewController ()
@property (nonatomic, strong) CAEmitterLayer *emitter;

//@property (nonatomic, strong) CALayer *layer;
@end

@implementation ThirtyoneViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"火焰";
    self.view.backgroundColor = [UIColor grayColor];
    
    [self createEmitterCell];
    [self.view.layer addSublayer:self.emitter];
    
}

- (void)createEmitterCell {
    //创建粒子
    CAEmitterCell *cell = [CAEmitterCell emitterCell];
    //配置粒子图像
    cell.contents = (__bridge id)[UIImage imageNamed:@"火焰"].CGImage;
    //粒子每秒发射个数
    cell.birthRate = 400;
    //粒子生命周期
    cell.lifetime = 3.0;
    //粒子旋转角度
    cell.spin = M_PI / 2;
    //粒子颜色
    cell.color = [UIColor colorWithRed:1.000 green:0.681 blue:0.178 alpha:1.000].CGColor;
    //粒子衰减过程
    cell.alphaSpeed -= 1;
    //粒子发射速度
    cell.velocity = 40;
    //粒子发射速度可变范围,如果此处设置为10 则速度值在30 - 50 之类变动
    cell.velocityRange = 10;
    //粒子缩放比例
    cell.scaleSpeed -= 1;
    //cell发射角度范围
    cell.emissionLongitude =  0;
    //cell发射偏转角度
    cell.emissionRange = M_PI / 4;
    //将配置好的粒子放入容器中
    self.emitter.emitterCells = @[cell];
    
}

- (CAEmitterLayer *)emitter {
    if (_emitter == nil) {
        //创建粒子图层容器
        CAEmitterLayer *layer = [CAEmitterLayer layer];
        //设置发射器位置
        layer.emitterPosition = self.view.center;
        //设置发射器范围
        layer.emitterSize = CGSizeMake(50, 30);
        //设置发射器形状
        layer.emitterShape = kCAEmitterLayerLine;
        //设置发射器发射模式
        layer.emitterMode = kCAEmitterLayerSurface;
        //设置发射器的渲染模式
        layer.renderMode = kCAEmitterLayerAdditive;
        
        _emitter = layer;
    }
    return _emitter;
}
@end